import React from 'react';
import ReactDOM from 'react-dom';
class App extends React.Component {
  // constructor() {
  //   super();
  //   this.state = {
  //     count: 100
  //   }
  // }
  state = {
    count: 100
  }
  add = () => {
    // console.log(this.state)
    // this.state.count++
    // console.log(this.state.count)
    // setState 更新数据大部分情况下 是一个异步操作；原生事件绑定的时候是一个同步
    // this.setState({
    //   count: this.state.count + 1
    // }, () => {
    //   // 数据更新完成之后触发
    //   console.log(this.state.count)
    // })
    // this.setState({})

    let obj1 = {
      count: this.state.count += 100 // count:200
    }
    this.setState(obj1, () => {
      console.log('1', this.state.count)
    })
    console.log(this.state.count)

    let obj2 = {
      count: this.state.count += 100 // count:200
    }
    this.setState(obj2, () => {
      console.log('2', this.state.count)
    })

    let obj3 = {
      count: this.state.count += 100 // count:200
    }
    this.setState(obj3, () => {
      console.log('3', this.state.count)
    })

    let obj4 = {
      count: this.state.count += 100 // count:200
    }
    this.setState(obj4, () => {
      console.log('4', this.state.count)
    })

  }
  render() {
    return <div className=''>
      <h1>{this.state.count}</h1>
      <button onClick={this.add}>+</button>
    </div>;
  }
}

ReactDOM.render(<App />, document.getElementById('root'))